package com.guiji.text2video.fastvideo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 生成id
 *
 * @author scl
 */
public class GeneratID {
    /**
     * 根据传入的时间表示格式，返回当前时间的格式 如果是yyyyMMdd，注意字母y不能大写。
     *
     * @param sformat yyyyMMddhhmmss
     * @return
     */
    public static String getDate(String sformat) {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(sformat);
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getRandomNum(int num) {
        String numStr = "";
        for (int i = 0; i < num; i++) {
            numStr += (int) (10 * (Math.random()));
        }
        return numStr;
    }

    /**
     * 生成id
     *
     * @return
     */
    public static String getJobGeneratID() {
        String sformat = "yyyyMMdd-HHmmss-";
        int num = 12;
        String idStr = "Job-" + getDate(sformat) + getRandomNum(num);
        return idStr;
    }

    /**
     * 根据zipid生成jobid
     * 保证-年月日-时分秒一致
     *
     * @return
     */
    public static String getJobGeneratIdWithZip(String zipId) {
        String[] zip = zipId.split("-");
        int num = 12;
        String idStr = "Job-" + zip[1] + "-" + zip[2] + "-" + getRandomNum(num);
        return idStr;
    }

    /**
     * 生成id
     *
     * @return
     */
    public static String getNLPGeneratID() {
        String sformat = "yyyyMMdd-HHmmss-";
        int num = 12;
        String idStr = "NLP-" + getDate(sformat) + getRandomNum(num);
        return idStr;
    }

    /**
     * 生成id
     *
     * @return
     */
    public static String getTTSGeneratID() {
        String sformat = "yyyyMMdd-HHmmss-";
        int num = 12;
        String idStr = "TTS-" + getDate(sformat) + getRandomNum(num);
        return idStr;
    }

    /**
     * 生成id
     *
     * @return
     */
    public static String getComposeGeneratID() {
        String sformat = "yyyyMMdd-HHmmss-";
        int num = 12;
        String idStr = "POS-" + getDate(sformat) + getRandomNum(num);
        return idStr;
    }

    /**
     * 生成id
     *
     * @return
     */
    public static String getZipGeneratID() {
        String sformat = "yyyyMMdd-HHmmss-";
        int num = 12;
        String idStr = "Zip-" + getDate(sformat) + getRandomNum(num);
        return idStr;
    }
}